package com._520it.wms.web.controller;

import com._520it.wms.domain.Department;
import com._520it.wms.domain.Employee;
import com._520it.wms.query.EmployeeQueryObject;
import com._520it.wms.query.PageResult;
import com._520it.wms.service.IDepartmentService;
import com._520it.wms.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by dd on 2017/11/15.
 */
@Controller
@RequestMapping("employee")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") EmployeeQueryObject qo){
        System.out.println(qo);
        System.out.println("====================");

        model.addAttribute("employees",employeeService.query(qo));
        model.addAttribute("departments",departmentService.listAll());
        return "employee/list";
    }

    @RequestMapping("input")
    public String input(Long id,Model model){
            model.addAttribute("employee", employeeService.get(id));
            model.addAttribute("departments",departmentService.listAll());
        return "employee/input";
    }

    @RequestMapping("delete")
    public String delete(Long id){
        employeeService.delete(id);
        return "redirect:/employee/list.do";
    }

    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(Employee employee){
        employeeService.saveOrUpdate(employee);
        return "redirect:/employee/list.do";
    }
}
